package com.itjiange.servlet;

import com.itjiange.constant.UserStatus;
import com.itjiange.pojo.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 用户登录
 *
 * @author ItJiange
 * @date 2023/10/24
 */
@WebServlet("/login")
public class UserLoginServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 获取用户名和密码
        String userName = req.getParameter("username");
        String userPassword = req.getParameter("password");
        // 创建对象
        User user = new User();
        user.setUserName(userName);
        user.setUserPassword(userPassword);
        // 存入 session
        req.getSession().setAttribute(UserStatus.USER_LOGIN_ING, user);
        System.out.println("用户登录");
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
